package cn.wh.mybatis.session;

import cn.wh.mybatis.binding.MapperRegistry;
import cn.wh.mybatis.mapping.MappedStatement;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description 配置项
 * @Version 1.0.0
 * @Date 2022/11/30 17:30
 * @Created wh
 */
public class Configuration {

    //映射注册机
    protected MapperRegistry mapperRegistry=new MapperRegistry(this);

    //映射语句 存在map里
    protected final Map<String, MappedStatement>mappedStatements=new HashMap<>();

    public void addMappers(String packageName){
        mapperRegistry.addMappers(packageName);
    }

    public <T> void addMapper(Class<T> type){
        mapperRegistry.addMapper(type);
    }

    public <T> T getMapper(Class<T> type, SqlSession sqlSession) {
        return mapperRegistry.getMapper(type, sqlSession);
    }

    public boolean hasMapper(Class<?> type) {
        return mapperRegistry.hasMapper(type);
    }

    public void addMappedStatement(MappedStatement ms){
        mappedStatements.put(ms.getId(),ms);
    }

    public MappedStatement getMappedStatement(String id) {
        return mappedStatements.get(id);
    }

}
